package com.luych.toolbox.common.feign.intf.docker.service;

import com.luych.toolbox.common.constant.PageConstant;
import com.luych.toolbox.common.feign.param.docker.service.DockerContainerParam;
import com.luych.toolbox.common.feign.view.docker.service.DockerContainerView;
import com.luych.toolbox.common.feign.view.docker.service.DockerStatDonutView;
import com.luych.toolbox.common.feign.view.docker.service.DockerStatLineView;
import com.luych.toolbox.common.page.CommonPageResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(contextId = "docker-service-docker-container", name = "docker-container", path = "/container", decode404 = true)
public interface DockerContainerFeign {

    @ApiOperation("按关键字查询")
    @GetMapping
    CommonPageResult<DockerContainerView> page(
            @ApiParam(value = "每页容量") @RequestHeader(name = "pageSize", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SIZE_STR) long pageSize,
            @ApiParam(value = "查询页码") @RequestHeader(name = "pageNumber", required = false, defaultValue = PageConstant.DEFAULT_PAGE_NUMBER_STR) long pageNumber,
            @ApiParam(value = "排序字段") @RequestHeader(name = "sort", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SORT) String sort,
            @ApiParam(value = "正序/倒序，取值ASC/DESC") @RequestHeader(name = "order", required = false, defaultValue = PageConstant.DEFAULT_PAGE_ORDER) String order,
            @ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
            @ApiParam(value = "查询关键字") @RequestParam(name = "keyword", required = false) String keyword);

    @ApiOperation("详情")
    @GetMapping("/{id}")
    DockerContainerView get(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                            @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("新增")
    @PostMapping
    DockerContainerView create(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                               @ApiParam(value = "数据信息") @RequestBody DockerContainerParam model
    );

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    void remove(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("启动")
    @PostMapping("/{id}/start")
    void start(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
               @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("停止")
    @PostMapping("/{id}/stop")
    void stop(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
              @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("重启")
    @PostMapping("/{id}/restart")
    void restart(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                 @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("杀掉")
    @PostMapping("/{id}/kill")
    void kill(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
              @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("暂停")
    @PostMapping("/{id}/pause")
    void pause(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
               @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("恢复")
    @PostMapping("/{id}/resume")
    void resume(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("重命名")
    @PostMapping("/{id}/rename")
    void rename(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                @ApiParam(value = "ID") @PathVariable(value = "id") String id,
                @ApiParam(value = "名称") @RequestParam("name") String name
    );

    @ApiOperation("日志")
    @GetMapping("/{id}/log")
    List<String> log(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                     @ApiParam(value = "ID") @PathVariable(value = "id") String id,
                     @ApiParam(value = "TAIL") @RequestParam(value = "tail", required = false, defaultValue = "100") long tail
    );

    @ApiOperation("CPU利用率环形图")
    @GetMapping("/{id}/cpu/donut")
    DockerStatDonutView cpuDonut(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                                 @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("CPU利用率折线图")
    @GetMapping("/{id}/cpu/line")
    DockerStatLineView cpuLine(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                               @ApiParam(value = "ID") @PathVariable(value = "id") String id,
                               @ApiParam(value = "时长(秒)") @RequestParam(value = "second", required = false, defaultValue = "600") Integer second,
                               @ApiParam(value = "显示日期") @RequestParam(value = "date", required = false, defaultValue = "false") Boolean date
    );

    @ApiOperation("内存利用率环形图")
    @GetMapping("/{id}/memory/donut")
    DockerStatDonutView memoryDonut(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                                    @ApiParam(value = "ID") @PathVariable(value = "id") String id
    );

    @ApiOperation("内存利用率折线图")
    @GetMapping("/{id}/memory/line")
    DockerStatLineView memoryLine(@ApiParam(value = "宿主机ID") @RequestParam("serverId") String serverId,
                                  @ApiParam(value = "ID") @PathVariable(value = "id") String id,
                                  @ApiParam(value = "时长(秒)") @RequestParam(value = "second", required = false, defaultValue = "600") Integer second,
                                  @ApiParam(value = "显示日期") @RequestParam(value = "date", required = false, defaultValue = "false") Boolean date
    );
}
